#!/usr/local/bin/python2.6
# coding: utf-8
import os
import sys
import smtplib
from email.mime.text import MIMEText

mailfrom = "yaozhongwei2011@tianya.cn"
mailpasswd = 'tianya2011'
mailserver = 'mx.tianya.cn'

def sendmail(mailto, subject, content):
    '''
    subject:主题
    content:内容
    '''
    msg = MIMEText(content, 'html', 'utf-8')
    msg['Subject'] = subject
    msg['From'] = mailfrom
    msg['To'] = ";".join(mailto)
        
    try:
        s = smtplib.SMTP()
        s.connect(mailserver)
        s.login(mailfrom, mailpasswd)
        s.sendmail(mailfrom, mailto, msg.as_string())
        s.close()
        return True
    except Exception, e:
        print str(e)
        return False

if __name__ == '__main__':
    file = sys.argv[2]
    f = open(file, "r")
    lines = ""
    while True:
        line = f.readline()
        if not line:
            break
        line = line.strip() + "<br \>"
        lines += line
    f.close()
    lines = '<html>%s</html>' % (lines)
    sendmail(sys.argv[1], "job info", lines)
